package com.gem.back.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gem.back.entity.AoaAttendsList;
import com.gem.back.entity.AoaUser;
import com.gem.back.mapper.AoaAttendsListMapper;
import com.gem.back.service.IAoaAttendsListService;
import com.gem.back.service.IAoaUserService;
import com.gem.utils.StatusDictUtils;
import com.gem.utils.TypeDictUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  考勤服务实现类
 * </p>
 *
 * @author hhhy
 * @since 2020-02-22
 */
@Service
public class AoaAttendsListServiceImpl extends ServiceImpl<AoaAttendsListMapper, AoaAttendsList> implements IAoaAttendsListService {

    @Autowired
    private AoaAttendsListMapper attendsListMapper;

    @Autowired
    private IAoaUserService aoaUserService;


    @Override
    public List<AoaAttendsList> findByAttendList(Integer currentPage, Integer pageCount, String userName) {
        if (userName == null) {
            userName = "";
        }
        return attendsListMapper.findByAttendList((currentPage - 1) * pageCount,pageCount,userName);
    }

    @Override
    public Integer getTotalPage(Integer pageCount, String userName) {
        if (userName == null) {
            userName = "";
        }
        Integer total = attendsListMapper.getTotal(userName);
        return (total - 1) / pageCount + 1;
    }

      @Override
    public void saveAttend(AoaAttendsList aoaAttendsList, HttpServletRequest request) {
        if (aoaAttendsList.getAttendsId() != null) {
           attendsListMapper.updateById(aoaAttendsList);
        } else {
           attendsListMapper.insert(aoaAttendsList);
        }
    }

    @Override
    public List<AoaAttendsList> findByParentId(Integer currentPage, Integer pageCount,String userName) {
        if (userName == null) {
            userName = "";
        }
        return attendsListMapper.findByParentId((currentPage - 1) * pageCount,pageCount,userName);
    }

    @Override
    public Integer getEmpTotal(Integer pageCount,Integer fatherId) {
    /*    if (fatherId == null) {
            fatherId = "";
        }*/
      /*  if (userName == null) {
            userName = "";
        }*/
        Integer total = attendsListMapper.getEmpTotal(fatherId);
        return (total - 1) / pageCount + 1;
    }


    @Override
    public Integer updatetime(Date date, String hourmin, Integer status, Integer attendsId) {
        return attendsListMapper.updatetime(date,hourmin,status,attendsId);
    }

    @Override
    public Integer findoffworkid(String nowdate, Integer userId) {
        return attendsListMapper.findoffworkid(nowdate,userId);
    }

    @Override
    public AoaAttendsList findlastest(String nowdate, Integer userId) {
        return attendsListMapper.findlastest(nowdate,userId);
    }

    @Override
    public List<AoaAttendsList> findAttendById(Integer currentPage, Integer pageCount, String userName) {
        if (userName == null) {
            userName = "";
        }
        return attendsListMapper.findAttendById((currentPage - 1) * pageCount,pageCount,userName);
    }

    @Override
    public Integer getMyTotal(Integer pageCount, String userName) {
        if (userName == null) {
            userName = "";
        }
        Integer total = attendsListMapper.getMyTotal(userName);
        return (total - 1) / pageCount + 1;
    }

    @Override
    public AoaAttendsList findById(Integer attendsId) {
        return attendsListMapper.findById(attendsId);
    }

    @Override
    public Integer countrecord(String nowdate, Integer userId) {
        return attendsListMapper.countrecord(nowdate,userId);
    }

}
